using System.IO;
using System.Net;
using System.Windows.Forms;
using System.Xml;

namespace EARogueCalc
{
    public static class Statics
    {
        public static readonly string ITEM_LIST_PATH = Application.CommonAppDataPath + "\\itemlist.xml";
        public static readonly string ITEM_LIST_XML_URI = "http://wow.allakhazam.com/itemlist.xml";
        public static readonly string ITEM_STATS_XML_URI = "http://wow.allakhazam.com/cluster/item-xml.pl?witem=";
        public static readonly string ITEM_DEFAULT_NONITEM = "ZZZZZ";
        public static readonly string ITEM_LITE_HTML_URL = "http://wow.allakhazam.com/ihtml?";

        public static string currentItemId;


        public static XmlDocument GetFeed(string URI)
        {
            HttpWebRequest rssFeed = (HttpWebRequest) WebRequest.Create(URI);
            rssFeed.UserAgent = "Firefox/2.0";
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(rssFeed.GetResponse().GetResponseStream());
            return xmlDoc;
        }

        public static string GetHTML(string URI)
        {
            HttpWebRequest htmlPage = (HttpWebRequest) WebRequest.Create(URI);
            htmlPage.UserAgent = "Firefox/2.0";
            StreamReader reader = new StreamReader(htmlPage.GetResponse().GetResponseStream());
            string ret = reader.ReadToEnd();
            return ret;
        }

        public static string GetItemId(string searchParam)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(ITEM_LIST_PATH);
            XmlNode node = doc.SelectSingleNode("/AkzItemList/wowitem[@name=\"" + searchParam + "\"]");
            if (node != null)
                return node.Attributes[1].Value;
            else
                return ITEM_DEFAULT_NONITEM;
        }
    }
}